<template>
	<view class="f26r colFff">
		<navbar background="background-image: linear-gradient(to right, #2c6739, #99c043);"
			title="会员卡" back @onBack="goBack" @topTotalHeight="topTotalHeight"
		></navbar>
		<view class="boSiBorBox"
			:style="'height: ' + 'calc(100vh - ' + calcNum + 'px);'"
		>
			<scroll-view scroll-y="true" class="hPer100"
				:refresher-enabled="true" :refresher-triggered="data0Tri"
				@refresherrefresh="orderRefresh"
			>
				<view class="borRad20r poRel h300r overHid mt30r ml40r mr40r bSha0010u0rgb00001"
					v-for="(item, index) in cardList" :key="item.id"
					@click="cliCardFun(item)"
				>
					<image :src="item.thumb ? item.thumb : '/static/images/logo.png'" mode="aspectFill"
						class="h300r wPer100"
					></image>
					<view class="poAbs top20r left20r w200r h40r backCol0a0a0aS5 teAliCenter borRad20r">
						时长：{{item.month}}个月
					</view>
					<view class="poAbs left0 bom0 backCol0a0a0aS5 wPer100 lh80r disFlex pl20r pr20r boSiBorBox">
						<view class="flex1">
							<!-- 所有门店通用会员月卡 5.00折优惠 -->
							购买/赠送：{{
								item.status == 1 ? '购买' :
								item.status == 2 ? '赠送' : item.status
							}}
						</view>
						<view class="w100r teAliRight">
							¥{{item.price}}
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
import navbar from '@/components/navbar.vue'
import { getShopCardruleList } from '@/utils/api.js'
import { baseUrl } from '@/utils/request.js'
export default {
	components: { navbar },
	data() {
		return {
			baseUrl,
			token: '',
			calcNum: 0,
			data0Tri: false, cardList: [],
			
		}
	},
	onShow() {
		const token = uni.getStorageSync('token');
		if(token) {
			this.token = token;
			this.getDataList1()
		}else {
			this.token = '';
		}
	},
	methods: {
		goBack() {
			uni.navigateBack();
		},
		topTotalHeight(height) {
			// #ifdef MP-WEIXIN
				this.calcNum = height;
			// #endif
			// #ifdef H5
				this.calcNum = 0;
			// #endif
		},
		getDataList1(callBack) {
			getShopCardruleList({token: this.token}).then(res => {
				// console.log('111', res)
				if(res.data && res.data.length) {
					this.cardList = res.data;
				}
				if(callBack) callBack();
			})
		},
		orderRefresh() {
			if(!this.data0Tri) {
				this.data0Tri = true;
				this.getDataList1(() => {
					this.data0Tri = false;
				});
			}
		},
		cliCardFun(item) {
			uni.navigateTo({
				url: '/pages/index/buyCard?item=' + JSON.stringify(item)
			})
		}
	}
}
</script>
<style>
</style>